package com.typy.www.tpay.ui.acitivity;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.zxing.qrcode.encoder.QRCode;
import com.typy.www.tpay.R;
import com.typy.www.tpay.base.BaseBackActivity;
import com.typy.www.tpay.constance.Constance;
import com.typy.www.tpay.constance.Sharep;
import com.typy.www.tpay.util.ClassHoldUtil;
import com.typy.www.tpay.util.Logutil;
import com.typy.www.tpay.util.PreferencesUtil;
import com.typy.www.tpay.util.QRcodeUtil;
import com.typy.www.tpay.util.SDFileUtil;
import com.typy.www.tpay.util.ToastUtil;
import com.typy.www.tpay.util.listviewanimations.IntentUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by 13799 on 2018/6/18.
 */

public class ShareActivity extends BaseBackActivity {

    @BindView(R.id.img_qrcode)
    ImageView imgQrcode;
    @BindView(R.id.tv_sharerecord)
    TextView tvSharerecord;

    public static void show(Context context) {
        IntentUtil.intent2Activity(context, ShareActivity.class);
    }

    @Override
    protected void initView() {
        super.initView();
        ButterKnife.bind(this);
        setTitle("分享");
        ((TextView) mBtnRight).setText("保存二维码");
        mBtnRight.setVisibility(View.VISIBLE);
        QRcodeUtil.setCode(PreferencesUtil.getValue(Sharep.SHAREURL),imgQrcode);
    }

    @Override
    protected void onRightButtonClick() {
        if(SDFileUtil.getInstance().saveBitmap(getActivity(), QRcodeUtil.getCode(PreferencesUtil.getValue(Sharep.SHAREURL), imgQrcode))) {
            ToastUtil.show(getActivity(),"二维码已保存");
        }else{
            ToastUtil.show(getActivity(),"二维码保存失败");
        }
    }

    @Override
    protected int getContentResId() {
        return R.layout.activity_share;
    }

    @OnClick(R.id.tv_sharerecord)
    public void onViewClicked() {
        RecordActivity.show(getActivity(), ClassHoldUtil.ShareRecord);
    }
}
